// miniprogram/pages/showView/signUp/shareActivity.js
let network = require("../../../utils/requestManager.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show_canvas:false,
    wei_canvas_data:{
      top_bg:"",
      title:"",
      qrcode:"",
      shop_name:""
    },
    canvasSrc:'',
    qrcode_path:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.hideShareMenu()//隐藏转发按钮
    console.log(options)
    let that = this;
    
    network.getRequest('apply/little/apply/product/detail?id=' + options.id,{},function(res){
      console.log(res)
      network.postRequest('xcx/create/qrcode', { page:"pages/showView/signUp/weiActivity",scene:"",width:"100"},function(qrcode_res){
        console.log(qrcode_res)
        

      //获取data内wei_canvas_data对象的key
      let canvas_bg = 'wei_canvas_data.top_bg'
      let canvas_title = 'wei_canvas_data.title'
      let canvas_shop_name = 'wei_canvas_data.shop_name'
      let canvas_qrcode = 'wei_canvas_data.qrcode'
      that.canvas_component = that.selectComponent("#wei_canvas_component");
      console.log("aaaaaaa")
      console.log(options.qrcode)
      //绘图之前先把banner图片缓存在本地
      wx.getImageInfo({
        src: res.detail.product.image_url,
        success:function(ress){
          console.log("缓存top_bg成功")
          console.log(ress)
          //赋值
          that.setData({
            [canvas_bg]: ress.path,
            [canvas_title]: res.detail.product.title,
            [canvas_shop_name]: res.detail.product.shop_title,
            [canvas_qrcode]: options.qrcode//获取跳转传的二维码
          })
          //获取canvas节点，调用内部函数绘图
          that.canvas_component.draw_canvas(that.data.wei_canvas_data)
        },
        fail:function(err){
          wx.showToast({
            title: '图片获取失败',
            icon:"none"
          })
        }

      })
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * canvas组件与page之间数据传递函数
   * 传递的是canvas生成的image
   * **/
  showCanvas:function(e){
    console.log(e.detail.canvas_image_data)
    let that = this;
    that.setData({
      canvasSrc: e.detail.canvas_image_data
    })
  },

  /**
   * 点击保存图片
   * 获取组件
   * 找到组件内的事件saveCanvasImg
   * **/
  save_canvas_btn:function(){
    let that = this;
    that.canvas_component = that.selectComponent("#wei_canvas_component");
    that.canvas_component.saveCanvasImg();
  },

  /**
   * 长按保存图片
   * 获取组件
   * 找到组件内的事件longTap
   * **/
  longtap_save_img:function(){
    let that = this;
    that.canvas_component = that.selectComponent("#wei_canvas_component");
    that.canvas_component.longTap();
  }
})